package com.example.bookstore.commons.utils;


import com.example.bookstore.commons.bean.result.JsonResult;
import com.example.bookstore.commons.bean.result.ResultCode;

/**
 * @author zmhzs
 */
public class JsonResultUtil {
    public static <T> JsonResult<T> success(T data) {
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.setSuccess(true);
        jsonResult.setErrorCode(200);
        jsonResult.setData(data);
        return jsonResult;
    }

    public static <T> JsonResult<T> fail(ResultCode resultEnum) {
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.setSuccess(false);
        jsonResult.setErrorCode(resultEnum.getCode());
        jsonResult.setErrorMsg(resultEnum.getMessage());
        return jsonResult;
    }
}